<?php 
## include required files
/*******************************/
require_once '../model/seo.php';
/*******************************/

## Create Objects
/*******************************/
$seoObj = new Model_SEO();
/*******************************/

$seo_id = base64_decode($_GET['id']);
$search =($_REQUEST['search']);
$order_field =($_REQUEST['order_field']);
	$order_by =($_REQUEST['order_by']);

	$smarty->assign('order_field', $order_field);
	$smarty->assign('order_by', $order_by);
	
	$smarty->assign('search', $search);
if(isset($_POST['editseo_btn'])) {
	## apply PHP validation for required filed
	if(trim($_POST['meta_title']) != '' && trim($_POST['meta_keyword']) != '' && trim($_POST['meta_description']) != '') {
		$seo_Array = array();
		
		extract($_POST);
		$seo_Array['meta_title']   		= return_post_value($meta_title);
		$seo_Array['meta_keyword']   	= return_post_value($meta_keyword);
		$seo_Array['meta_description']   = return_post_value($meta_description);
		
		$seoObj->editSeoById($seo_Array,$seo_id);
	
		$_SESSION['msg'] = "<div class='success_msg'><span>SEO updated successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=seo&page='.$_GET['page'].'&order_field='.$_GET['order_field'].'&order_by='.$_GET['order_by'].'&search='.$_GET['search']);
		exit;
	} else { // php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please enter all required fields.</span></div>';
	}
	// main if closed
}

## Fetch seo category by id
if($_GET['id'] != ''&& $_GET['action'] == 'edit') {
	
	$smarty->assign('page', $_GET['page']);
	$seoArray = $seoObj->getSeoDetailsById($seo_id);	
	$smarty->assign('seoArray', $seoArray);
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'seo');
$smarty->assign('mainmenu', '6');
## Unset all the objects created which are on this page
unset($seoObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'seo/editseo.tpl');
unset($smarty);
?>